package robocup.testing;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.LinkedList;

import robocup.component.geometry.Vektor;
import robocup.component.geometry.analysers.PossibleBallsAfterPoweredAcc;
import robocup.component.geometry.analysers.ReachableArea;
import robocup.component.worldobjects.Ball;
import robocup.component.worldobjects.Player;


/**
 * @author Thomas Karbe
 *
 */
public class TestPoweredAndReachable
    extends GraphicalTestFrame {
  
  Player p1;
  Player p2;
  ReachableArea ra;
  PossibleBallsAfterPoweredAcc possBalls;
  Ball b;
  LinkedList<Vektor> list;
  LinkedList<Vektor> list2;

  /**
   * 
   */
  public TestPoweredAndReachable() {

    super();

  }

  /**
   * @param d
   */
  public TestPoweredAndReachable(
      Dimension d) {

    super(d);

  }

  /**
   * @param center
   */
  public TestPoweredAndReachable(
      Vektor center) {

    super(center);

  }

  /**
   * @param d
   * @param center
   */
  public TestPoweredAndReachable(
      Dimension d,
      Vektor center) {

    super(d, center);

  }

  /**
   * @param scale
   */
  public TestPoweredAndReachable(
      double scale) {

    super(scale);

  }

  /**
   * @param d
   * @param scale
   */
  public TestPoweredAndReachable(
      Dimension d,
      double scale) {

    super(d, scale);

  }

  /**
   * @param center
   * @param scale
   */
  public TestPoweredAndReachable(
      Vektor center,
      double scale) {

    super(center, scale);

  }

  /**
   * @param d
   * @param center
   * @param scale
   */
  public TestPoweredAndReachable(
      Dimension d,
      Vektor center,
      double scale) {

    super(d, center, scale);

  }

  /** (non-Javadoc)
   * @see robocup.testing.GraphicalTestFrame#nextSituation()
   */
  @Override
  protected void nextSituation() {
    p1= rand.getRandomPlayer();
    setCenter(p1.getPosition());
    Vektor pos= p1.getPosition();
    p2= rand.getRandomPlayer(pos.x-4, pos.x+4, pos.y-4, pos.y+4);
    b= rand.getRandomBallInKickable(p1);
    ra= new ReachableArea(1, p2, p2.getKickDistance());
    possBalls= new PossibleBallsAfterPoweredAcc(p1,b,rand.getRandomDouble(0, 100));
    list= possBalls.getIntersectionPoints(ra, true);
    list2= new LinkedList<Vektor>();
    for (Vektor v: list) {
      list2.add(v);
    }
    try {
      possBalls.filterShortPoints(list2);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  /** (non-Javadoc)
   * @see robocup.testing.GraphicalTestFrame#nextCycle()
   */
  @Override
  protected void nextCycle() {
    ra.setArea(ra.getCycles()+1, p2, p2.getKickDistance());
    possBalls.extrapolateThis();
    list.clear();
    list2.clear();
    possBalls.addIntersectionPointsToList(ra, true, list);
    for (Vektor v: list) {
      list2.add(v);
    }
    try {
      possBalls.filterShortPoints(list2);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  /** (non-Javadoc)
   * @see robocup.testing.GraphicalTestFrame#paintSituation(java.awt.Graphics)
   */
  @Override
  protected void paintSituation(Graphics g) {
    g.setColor(Color.orange);
    drawKickable(g, p1);
    drawMovement(g, p1);
    drawMovement(g, p2);
    drawMovement(g, b);
    g.setColor(Color.YELLOW);
    draw(g,p1);
    g.setColor(Color.red);
    draw(g,p2);
    g.setColor(Color.black);
    draw(g,b);
    draw(g,ra,true);
    g.setColor(Color.blue);
    draw(g,possBalls);
    g.setColor(Color.red);
    draw(g,list);
    g.setColor(Color.green);
    draw(g,list2);
  }

  /**
   * @param args
   */
  public static void main(String[] args) {
    new TestPoweredAndReachable();
  }

}
